using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UI;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;

namespace UI
{
    public class UI_ButtonSelectPanel : BasePanel
    {
        private Button LeftButton;
        private Button RightButton;
        public TMP_Text leftTextMeshPro;
        public TMP_Text rightTextMeshPro;
        public override EPanelAttr GetPanelAttr => EPanelAttr.None;
        public override EPanelLayer GetPanelLayer => EPanelLayer.Background;

        private ScenarioTrigger m_scenarioTrigger;

        private int leftScenarioId;
        private string leftScenarioName;
        private int rightScenarioId;
        private string rightScenarioName;
        
        internal override void Init()
        {
            LeftButton = transform.Find("LeftButton").GetComponent<Button>();
            RightButton = transform.Find("RightButton").GetComponent<Button>();

            m_scenarioTrigger=gameObject.GetComponent<ScenarioTrigger>();
            
            LeftButton.onClick.AddListener(() =>
            {
                m_scenarioTrigger.scenarioId = leftScenarioId;
                m_scenarioTrigger.scenarioName = leftScenarioName;
                m_scenarioTrigger.Trigger();
                Destroy(gameObject);
            });
            RightButton.onClick.AddListener(() =>
            {
                m_scenarioTrigger.scenarioId = rightScenarioId;
                m_scenarioTrigger.scenarioName = rightScenarioName;
                m_scenarioTrigger.Trigger();
                Destroy(gameObject);
            });
            /*transform.Find("RightButton").GetComponent<Button>().onClick.AddListener(() =>
            {
              
            });*/
        }

        public void setName(string leftName, string rightName)
        {
            leftTextMeshPro.text = leftName;
            rightTextMeshPro.text = rightName;
        }

        public void LeftButtonSet(int scenarioId,string scenarioName)
        {
            leftScenarioId = scenarioId;
            leftScenarioName = scenarioName;
        }

        public void RightButtonSet(int scenarioId, string scenarioName)
        {
           rightScenarioId = scenarioId;
           rightScenarioName = scenarioName;
        }
    }
}

